import LogicFlow from '@logicflow/core'
import { propertyPanelMap, propertyPanelRef } from './Common'

export const eventInit = (lf: LogicFlow) => {
  const { eventCenter } = lf.graphModel
  // 节点单机事件
  eventCenter.on('node:click', ({ data, e, position }) => {
    const nodeModel = lf.getNodeModelById(data.id)
    const component = propertyPanelMap.get(data.type)
    if (component) {
      propertyPanelRef.value.init({...nodeModel.getProperties(),id: nodeModel.id}, component,(value)=>{
        lf.setProperties(nodeModel.id, value);
      })
    } else {
      propertyPanelRef.value.close()
    }
    console.log('node:click', data, e, position,nodeModel)
  })
  // 画布单机事件
  eventCenter.on('blank:click', () => {
    propertyPanelRef.value.close()
  })
}
